package com.pengcheng.taskapplication.mvp.view.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.adapter.FragmentAdapter;
import com.pengcheng.taskapplication.contants.ConstantValue;
import com.pengcheng.taskapplication.model.TabItem;
import com.pengcheng.taskapplication.rxbus.RxBus;
import com.pengcheng.taskapplication.rxbus.RxBusRoute;
import com.pengcheng.taskapplication.rxbus.RxEvent;
import com.pengcheng.taskapplication.util.SPUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class OrderFragment extends BaseFragment{

    @BindView(R.id.tb_top)
    TabLayout tabLayout;
    @BindView(R.id.vp_show)
    ViewPager viewPager;

    private List<Fragment> fragmentList =new ArrayList<Fragment>();
    private List<TabItem> tabItemList = new ArrayList<>();

    @Override
    protected int layoutResID() {
        return R.layout.fragment_my_park_wash_list_layout;
    }

    @Override
    protected void initData() {
        int tab = getActivity().getIntent().getIntExtra(ConstantValue.IntentKey.KEY_FROM_TYPE, 0);
        TabItem tabItem=new TabItem();
        tabItem.setName("洗车");
        tabItemList.add(tabItem);
        TabItem tabItem2=new TabItem();
        tabItem2.setName("停车");
        tabItemList.add(tabItem2);

        MyWashListFragment washListFragment = new MyWashListFragment();
        fragmentList.add(washListFragment);
        MyParkListFragment parkListFragment=new MyParkListFragment();
        fragmentList.add(parkListFragment);

        FragmentAdapter adapter = new FragmentAdapter(getActivity().getSupportFragmentManager(), tabItemList, fragmentList);
        viewPager.setOffscreenPageLimit(fragmentList.size());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setCurrentItem(tab);
    }



    @Override
    protected boolean isRegistRxBus() {
        return true;
    }

    /**
     * 注册订阅事件
     */
    protected void receiveEvent(RxEvent rxEvent) {
        switch (rxEvent.busName) {
            case RxBusRoute.ParkOrder:
                if(viewPager!=null) {
                    viewPager.setCurrentItem(1);
                }
                break;
            case RxBusRoute.WashOrder:
                if(viewPager!=null) {
                    viewPager.setCurrentItem(0);
                }
                break;

        }
    }



}
